using AiQiuQuan.Sport.Model.Models;
using AiQiuQuan.Sport.Core;
using AiQiuQuan.Sport.WebApi.Services;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel.DataAnnotations;

namespace AiQiuQuan.Sport.WebApi.Controllers
{
    /// <summary>
    /// 平台约球管理
    /// </summary>
    public class PlatformBallController : PcApiController
    {
        private readonly IBallService _ballService;

        /// <summary>
        /// 平台约球管理
        /// </summary>
        public PlatformBallController(
            IBallService ballService
            )
        {
            _ballService = ballService;
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="id">约球ID</param>
        [HttpGet("get")]
        public async Task<UnaryResult<BallDto>> GetAsync([Required] Guid id)
        {
            var result = await _ballService.GetAsync(id);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 约球查询
        /// </summary>
        [HttpPost("query")]
        public async Task<UnaryResult<BallDto>> QueryAsync(BallQueryDto request)
        {
            request.IsPlatform = true;
            var result = await _ballService.QueryAsync(request);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        [HttpPost("pagelist")]
        public async Task<UnaryResult<PageResult<BallDto>>> PageListAsync(BallPageRequestDto request)
        {
            request.IsPlatform = true;
            var result = await _ballService.PageListAsync(request);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 新增
        /// </summary>
        [HttpPost("add")]
        public async Task<UnaryResult> AddAsync(BallAddDto model)
        {
            model.IsPlatform = true;
            var result = await _ballService.AddAsync(model);
            return result;
        }

        /// <summary>
        /// 修改
        /// </summary>
        [HttpPost("update")]
        public async Task<UnaryResult> UpdateAsync(BallUpdateDto model)
        {
            var result = await _ballService.UpdateAsync(model);
            return result;
        }

        /// <summary>
        /// 修改约球状态
        /// </summary>
        [HttpPost("update_state")]
        public async Task<UnaryResult> UpdateStateAsync(BallStateUpdateDto request)
        {
            var result = await _ballService.UpdateStateAsync(request);
            return result;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">约球ID</param>
        [HttpGet("delete")]
        public async Task<UnaryResult> DeleteAsync([Required] Guid id)
        {
            var result = await _ballService.DeleteAsync(id);
            return result;
        }

        /// <summary>
        /// 获取约球用户列表
        /// </summary>
        [HttpPost("list_join_user")]
        public async Task<UnaryResult<List<BallUserDto>>> GetBallUserListAsync(BallUserQueryDto request)
        {
            request.IsPlatform = true;
            var result = await _ballService.GetBallUserListAsync(request);
            return UnaryResult.Succeed(result);
        }

        /// <summary>
        /// 通过订单ID获取约球用户列表
        /// </summary>
        /// <param name="orderId">约球订单ID</param>
        [HttpGet("list_join_user_by_orderid")]
        public async Task<UnaryResult<List<BallUserDto>>> GetBallUserListByOrderIdAsync(Guid orderId)
        {
            var result = await _ballService.GetBallUserListByOrderIdAsync(orderId);
            return UnaryResult.Succeed(result);
        }
    }
}
